package org.exeed.controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import org.exeed.bean.ResultBean;
import org.exeed.entity.ImageEntity;
import org.exeed.entity.PdfEntity;
import org.exeed.entity.VideoEntity;
import org.exeed.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.nio.file.Path;
import java.nio.file.Paths;

//@CrossOrigin
@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    @PostMapping("/saveVideo")
    public ResultBean saveVideo(@RequestBody VideoEntity videoEntity) {

        resourceService.saveVideo(videoEntity);

        return ResultBean.succeed();
    }

    @GetMapping("/selectVideoPages")
    public ResultBean selectVideoPages(@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("key") String key) {
        return ResultBean.succeed(resourceService.selectVideoList(page, size, key));
    }

    @GetMapping("/getVideoById")
    public ResultBean getVideoById(@RequestParam("id") Long id) {
        return ResultBean.succeed(resourceService.selectVideoById(id));
    }

    @GetMapping("/deleteVideo")
    public ResultBean deleteVideo(@RequestParam("id") Long id) {
        resourceService.deleteVideoById(id);
        return ResultBean.succeed();
    }

    @PostMapping("/saveImage")
    public ResultBean saveImage(@RequestBody ImageEntity imageEntity) {

        resourceService.saveImage(imageEntity);

        return ResultBean.succeed();
    }

    @GetMapping("/selectImagePages")
    public ResultBean selectImagePages(@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("key") String key) {
        return ResultBean.succeed(resourceService.selectImageList(page, size, key));
    }

    @GetMapping("/getImageById")
    public ResultBean getImageById(@RequestParam("id") Long id) {
        return ResultBean.succeed(resourceService.selectImageById(id));
    }

    @GetMapping("/deleteImage")
    public ResultBean deleteImage(@RequestParam("id") Long id) {
        resourceService.deleteImageById(id);
        return ResultBean.succeed();
    }


    @PostMapping("/savePdf")
    public ResultBean savePdf(@RequestBody PdfEntity pdfEntity) {

        resourceService.savePdf(pdfEntity);
        return ResultBean.succeed();
    }

    @GetMapping("/selectPdfPages")
    public ResultBean selectPdfPages(@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("key") String key) {
        return ResultBean.succeed(resourceService.selectPdfList(page, size, key));
    }

    @GetMapping("/getPdfById")
    public ResultBean getPdfById(@RequestParam("id") Long id) {
        return ResultBean.succeed(resourceService.selectPdfById(id));
    }

    @GetMapping("/deletePdf")
    public ResultBean deletePdf(@RequestParam("id") Long id) {
        resourceService.deletePdfById(id);
        return ResultBean.succeed();
    }

}
